<?php
    class Pages_model extends CI_Model {
        
        function __construct() {
            parent::__construct();
        }
        
        public function get_last_entries(){
            $this->db->order_by('id_page', 'desc');
            $query = $this->db->get('page_groups', 20);
            return $query->result_array();
        }
        
        public function get_parent($id){
            if ($id == 0)
                return 'Корень';
            else {
                $this->db->select('title');
                $this->db->where('id_page', $id);
                $query = $this->db->get('page_groups');
                $parent = $query->result_array();
                return $parent['0']['title'];
            }
        }
        
        public function insert_one_entrie($data){
            $this->db->insert('page_groups', $data);
        }
        
        function drop_one_entrie($id){
            $this->db->where('id_page', $id);
            $this->db->or_where('id_parent', $id);
            $this->db->delete('page_groups');
        }
        
        function get_one_entrie($id) {
            $this->db->where('id_page', $id);
            $query = $this->db->get('page_groups');
            return $query->result_array();
        }
        
        function update_one_entrie($id, $data) {
            $this->db->where('id_page', $id);
            $this->db->update('page_groups', $data);
        }
    }
?>